import { computed, reactive, ref } from "vue";
import { tableColumnMap, statisticsColumnMap } from "../data";

export default function InitHook() {
  const activeKey = ref<string>("0");
  const pageStat = ref<Base.GeneraDataType>({
    0: 0,
    1: 0,
    2: 0,
    3: 0
  });
  const searchForm = reactive<PaymentApproval.SearchForm>({
    beforePageNum: 0,
    waybillNum: "",
    payableStatementNumber: "",
    agentIdList: [],
    statementType: "",
    companyIdList: [],
    pageNum: 1,
    pageSize: 100,
    total: 0
  });
  const tableData = ref<PaymentApproval.ListRows[]>([]);
  const tableRef = ref<any>(null);
  const drawerOpts = reactive<Base.DrawerOpts>({
    title: "",
    width: "520px",
    component: "",
    visible: false,
    type: 1,
    passData: {}
  });
  const dialogOpts = reactive<Base.DialogOpts>({
    title: "",
    width: "520px",
    component: "",
    visible: false,
    type: 1,
    passData: {}
  });
  const tableColumn = computed<Array<SuperTable.NestTableColumnItem | SuperTable.TableCoulmnItem>>(() => {
    return tableColumnMap[activeKey.value] || [];
  });
  const statisticsColumn = computed<Array<{ field: string; label: string }>>(() => {
    return statisticsColumnMap[activeKey.value] || [];
  });
  return {
    searchForm,
    tableData,
    tableRef,
    drawerOpts,
    dialogOpts,
    activeKey,
    pageStat,
    tableColumn,
    statisticsColumn
  };
}
